using System.Runtime.InteropServices;
using System;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace NativeWiFiLibrary
{
    static internal class WlanApi
    {
        internal const int WLAN_API_VERSION_1_0 = 0x00000001;
        internal const int WLAN_API_VERSION_2_0 = 0x00000002;
        internal const int WLAN_API_VERSION = WLAN_API_VERSION_2_0;
        internal const int WLAN_MAX_NAME_LENGTH = 256;
        internal const int WLAN_PROFILE_GROUP_POLICY = 0x00000001;
        internal const int WLAN_PROFILE_USER = 0x00000002;
        internal const int WLAN_PROFILE_CONNECTION_MODE_SET_BY_CLIENT = 0x00010000;
        internal const int WLAN_PROFILE_CONNECTION_MODE_AUTO = 0x00020000;
        internal const int WLAN_SET_EAPHOST_DATA_ALL_USERS = 0x00000001;

        internal enum WlanInterfaceState
        {
            NotReady = 0,
            Connected,
            AdHocNetworkFormed,
            Disconnecting,
            Disconnected,
            Associating,
            Discovering,
            Authenticating
        }

        [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
        internal struct WLAN_PROFILE_INFO
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = WLAN_MAX_NAME_LENGTH)]
            internal string strProfileName;
            internal uint dwFlags;
        };

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct DOT11_NETWORK
        {
            internal DOT11_SSID dot11Ssid;
            internal DOT11_BSS_TYPE dot11BssType;
        };

        internal const int DOT11_PSD_IE_MAX_DATA_SIZE = 240;
        internal const int DOT11_PSD_IE_MAX_ENTRY_NUMBER = 5;
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WlanRawData
        {
            internal uint dwDataSize;
            [MarshalAs(UnmanagedType.ByValArray)]
            internal byte[][] DataBlob;
        };

        // *****************************
        // * Nested elements not supported
        // *****************************
        // typedef struct _WLAN_RAW_DATA_LIST {
        //     Int32 dwTotalSize;
        //     Int32 dwNumberOfItems;
        //     struct {
        //         Int32 dwDataOffset;
        //         Int32 dwDataSize;
        //     } DataList[1];
        // } WLAN_RAW_DATA_LIST, *PWLAN_RAW_DATA_LIST;
        // *****************************

        internal enum WLAN_CONNECTION_MODE
        {
            wlan_connection_mode_profile = 0,
            wlan_connection_mode_temporary_profile,
            wlan_connection_mode_discovery_secure,
            wlan_connection_mode_discovery_unsecure,
            wlan_connection_mode_auto,
            wlan_connection_mode_invalid,
        };

        internal const int WLAN_REASON_CODE_SUCCESS = L2_REASON_CODE_SUCCESS;
        internal const int WLAN_REASON_CODE_UNKNOWN = L2_REASON_CODE_UNKNOWN;
        internal const int WLAN_REASON_CODE_RANGE_SIZE = L2_REASON_CODE_GROUP_SIZE;
        internal const int WLAN_REASON_CODE_BASE = L2_REASON_CODE_DOT11_AC_BASE;
        internal const int WLAN_REASON_CODE_AC_BASE = L2_REASON_CODE_DOT11_AC_BASE;
        internal const int WLAN_REASON_CODE_AC_CONNECT_BASE = 2;
        internal const int WLAN_REASON_CODE_AC_END = 1;
        internal const int WLAN_REASON_CODE_PROFILE_BASE = L2_REASON_CODE_PROFILE_BASE;
        internal const int WLAN_REASON_CODE_PROFILE_CONNECT_BASE = 2;
        internal const int WLAN_REASON_CODE_PROFILE_END = 1;
        internal const int WLAN_REASON_CODE_MSM_BASE = L2_REASON_CODE_DOT11_MSM_BASE;
        internal const int WLAN_REASON_CODE_MSM_CONNECT_BASE = 2;
        internal const int WLAN_REASON_CODE_MSM_END = 1;
        internal const int WLAN_REASON_CODE_MSMSEC_BASE = L2_REASON_CODE_DOT11_SECURITY_BASE;
        internal const int WLAN_REASON_CODE_MSMSEC_CONNECT_BASE = 2;
        internal const int WLAN_REASON_CODE_MSMSEC_END = 1;
        internal const int WLAN_REASON_CODE_NETWORK_NOT_COMPATIBLE = +1;
        internal const int WLAN_REASON_CODE_PROFILE_NOT_COMPATIBLE = +2;
        internal const int WLAN_REASON_CODE_NO_AUTO_CONNECTION = +1;
        internal const int WLAN_REASON_CODE_NOT_VISIBLE = +2;
        internal const int WLAN_REASON_CODE_GP_DENIED = +3;
        internal const int WLAN_REASON_CODE_USER_DENIED = +4;
        internal const int WLAN_REASON_CODE_BSS_TYPE_NOT_ALLOWED = +5;
        internal const int WLAN_REASON_CODE_IN_FAILED_LIST = +6;
        internal const int WLAN_REASON_CODE_IN_BLOCKED_LIST = +7;
        internal const int WLAN_REASON_CODE_SSID_LIST_TOO_LONG = +8;
        internal const int WLAN_REASON_CODE_CONNECT_CALL_FAIL = +9;
        internal const int WLAN_REASON_CODE_SCAN_CALL_FAIL = +10;
        internal const int WLAN_REASON_CODE_NETWORK_NOT_AVAILABLE = +11;

        internal const int WLAN_REASON_CODE_PROFILE_CHANGED_OR_DELETED = +12;
        internal const int WLAN_REASON_CODE_KEY_MISMATCH = 13;
        internal const int WLAN_REASON_CODE_USER_NOT_RESPOND = 14;
        internal const int WLAN_REASON_CODE_INVALID_PROFILE_SCHEMA = +1;
        internal const int WLAN_REASON_CODE_PROFILE_MISSING = +2;
        internal const int WLAN_REASON_CODE_INVALID_PROFILE_NAME = +3;
        internal const int WLAN_REASON_CODE_INVALID_PROFILE_TYPE = +4;
        internal const int WLAN_REASON_CODE_INVALID_PHY_TYPE = +5;
        internal const int WLAN_REASON_CODE_MSM_SECURITY_MISSING = +6;
        internal const int WLAN_REASON_CODE_IHV_SECURITY_NOT_SUPPORTED = +7;
        internal const int WLAN_REASON_CODE_IHV_OUI_MISMATCH = +8;
        internal const int WLAN_REASON_CODE_IHV_OUI_MISSING = +9;
        internal const int WLAN_REASON_CODE_IHV_SETTINGS_MISSING = +10;
        internal const int WLAN_REASON_CODE_CONFLICT_SECURITY = +11;
        internal const int WLAN_REASON_CODE_SECURITY_MISSING = +12;
        internal const int WLAN_REASON_CODE_INVALID_BSS_TYPE = +13;
        internal const int WLAN_REASON_CODE_INVALID_ADHOC_CONNECTION_MODE = +14;
        internal const int WLAN_REASON_CODE_NON_BROADCAST_SET_FOR_ADHOC = +15;
        internal const int WLAN_REASON_CODE_AUTO_SWITCH_SET_FOR_ADHOC = +16;
        internal const int WLAN_REASON_CODE_AUTO_SWITCH_SET_FOR_MANUAL_CONNECTION = +17;
        internal const int WLAN_REASON_CODE_IHV_SECURITY_ONEX_MISSING = +18;
        internal const int WLAN_REASON_CODE_PROFILE_SSID_INVALID = +19;
        internal const int WLAN_REASON_CODE_TOO_MANY_SSID = +20;
        internal const int WLAN_REASON_CODE_UNSUPPORTED_SECURITY_SET_BY_OS = +1;
        internal const int WLAN_REASON_CODE_UNSUPPORTED_SECURITY_SET = +2;

        internal const int WLAN_REASON_CODE_BSS_TYPE_UNMATCH = +3;
        internal const int WLAN_REASON_CODE_PHY_TYPE_UNMATCH = +4;
        internal const int WLAN_REASON_CODE_DATARATE_UNMATCH = +5;
        internal const int WLAN_REASON_CODE_USER_CANCELLED = WLAN_REASON_CODE_MSM_CONNECT_BASE + 1;
        internal const int WLAN_REASON_CODE_ASSOCIATION_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 2;
        internal const int WLAN_REASON_CODE_ASSOCIATION_TIMEOUT = WLAN_REASON_CODE_MSM_CONNECT_BASE + 3;
        internal const int WLAN_REASON_CODE_PRE_SECURITY_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 4;
        internal const int WLAN_REASON_CODE_START_SECURITY_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 5;
        internal const int WLAN_REASON_CODE_SECURITY_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 6;
        internal const int WLAN_REASON_CODE_SECURITY_TIMEOUT = WLAN_REASON_CODE_MSM_CONNECT_BASE + 7;
        internal const int WLAN_REASON_CODE_ROAMING_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 8;
        internal const int WLAN_REASON_CODE_ROAMING_SECURITY_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 9;
        internal const int WLAN_REASON_CODE_ADHOC_SECURITY_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 10;
        internal const int WLAN_REASON_CODE_DRIVER_DISCONNECTED = WLAN_REASON_CODE_MSM_CONNECT_BASE + 11;
        internal const int WLAN_REASON_CODE_DRIVER_OPERATION_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 12;
        internal const int WLAN_REASON_CODE_IHV_NOT_AVAILABLE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 13;
        internal const int WLAN_REASON_CODE_IHV_NOT_RESPONDING = WLAN_REASON_CODE_MSM_CONNECT_BASE + 14;
        internal const int WLAN_REASON_CODE_DISCONNECT_TIMEOUT = WLAN_REASON_CODE_MSM_CONNECT_BASE + 15;
        internal const int WLAN_REASON_CODE_INTERNAL_FAILURE = WLAN_REASON_CODE_MSM_CONNECT_BASE + 16;
        internal const int WLAN_REASON_CODE_UI_REQUEST_TIMEOUT = WLAN_REASON_CODE_MSM_CONNECT_BASE + 17;
        internal const int WLAN_REASON_CODE_TOO_MANY_SECURITY_ATTEMPTS = WLAN_REASON_CODE_MSM_CONNECT_BASE + 18;
        internal const int WLAN_REASON_CODE_MSMSEC_MIN = WLAN_REASON_CODE_MSMSEC_BASE;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_KEY_INDEX = WLAN_REASON_CODE_MSMSEC_BASE + 1;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_PSK_PRESENT = WLAN_REASON_CODE_MSMSEC_BASE + 2;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_KEY_LENGTH = WLAN_REASON_CODE_MSMSEC_BASE + 3;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_PSK_LENGTH = WLAN_REASON_CODE_MSMSEC_BASE + 4;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_NO_AUTH_CIPHER_SPECIFIED = WLAN_REASON_CODE_MSMSEC_BASE + 5;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_TOO_MANY_AUTH_CIPHER_SPECIFIED = WLAN_REASON_CODE_MSMSEC_BASE + 6;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_DUPLICATE_AUTH_CIPHER = WLAN_REASON_CODE_MSMSEC_BASE + 7;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_RAWDATA_INVALID = WLAN_REASON_CODE_MSMSEC_BASE + 8;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_AUTH_CIPHER = WLAN_REASON_CODE_MSMSEC_BASE + 9;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_ONEX_DISABLED = WLAN_REASON_CODE_MSMSEC_BASE + 10;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_ONEX_ENABLED = WLAN_REASON_CODE_MSMSEC_BASE + 11;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_PMKCACHE_MODE = WLAN_REASON_CODE_MSMSEC_BASE + 12;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_PMKCACHE_SIZE = WLAN_REASON_CODE_MSMSEC_BASE + 13;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_PMKCACHE_TTL = WLAN_REASON_CODE_MSMSEC_BASE + 14;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_PREAUTH_MODE = WLAN_REASON_CODE_MSMSEC_BASE + 15;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_PREAUTH_THROTTLE = WLAN_REASON_CODE_MSMSEC_BASE + 16;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_PREAUTH_ONLY_ENABLED = WLAN_REASON_CODE_MSMSEC_BASE + 17;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_NETWORK = WLAN_REASON_CODE_MSMSEC_BASE + 18;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_NIC = WLAN_REASON_CODE_MSMSEC_BASE + 19;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_PROFILE = WLAN_REASON_CODE_MSMSEC_BASE + 20;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_DISCOVERY = WLAN_REASON_CODE_MSMSEC_BASE + 21;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_PASSPHRASE_CHAR = WLAN_REASON_CODE_MSMSEC_BASE + 22;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_KEYMATERIAL_CHAR = WLAN_REASON_CODE_MSMSEC_BASE + 23;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_WRONG_KEYTYPE = WLAN_REASON_CODE_MSMSEC_BASE + 24;
        internal const int WLAN_REASON_CODE_MSMSEC_MIXED_CELL = WLAN_REASON_CODE_MSMSEC_BASE + 25;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_AUTH_TIMERS_INVALID = WLAN_REASON_CODE_MSMSEC_BASE + 26;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_INVALID_GKEY_INTV = WLAN_REASON_CODE_MSMSEC_BASE + 27;
        internal const int WLAN_REASON_CODE_MSMSEC_TRANSITION_NETWORK = WLAN_REASON_CODE_MSMSEC_BASE + 28;
        internal const int WLAN_REASON_CODE_MSMSEC_PROFILE_KEY_UNMAPPED_CHAR = WLAN_REASON_CODE_MSMSEC_BASE + 29;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_PROFILE_AUTH = WLAN_REASON_CODE_MSMSEC_BASE + 30;
        internal const int WLAN_REASON_CODE_MSMSEC_CAPABILITY_PROFILE_CIPHER = WLAN_REASON_CODE_MSMSEC_BASE + 31;
        internal const int WLAN_REASON_CODE_MSMSEC_UI_REQUEST_FAILURE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 1;
        internal const int WLAN_REASON_CODE_MSMSEC_AUTH_START_TIMEOUT = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 2;
        internal const int WLAN_REASON_CODE_MSMSEC_AUTH_SUCCESS_TIMEOUT = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 3;
        internal const int WLAN_REASON_CODE_MSMSEC_KEY_START_TIMEOUT = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 4;
        internal const int WLAN_REASON_CODE_MSMSEC_KEY_SUCCESS_TIMEOUT = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 5;
        internal const int WLAN_REASON_CODE_MSMSEC_M3_MISSING_KEY_DATA = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 6;
        internal const int WLAN_REASON_CODE_MSMSEC_M3_MISSING_IE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 7;
        internal const int WLAN_REASON_CODE_MSMSEC_M3_MISSING_GRP_KEY = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 8;
        internal const int WLAN_REASON_CODE_MSMSEC_PR_IE_MATCHING = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 9;
        internal const int WLAN_REASON_CODE_MSMSEC_SEC_IE_MATCHING = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 10;
        internal const int WLAN_REASON_CODE_MSMSEC_NO_PAIRWISE_KEY = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 11;
        internal const int WLAN_REASON_CODE_MSMSEC_G1_MISSING_KEY_DATA = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 12;
        internal const int WLAN_REASON_CODE_MSMSEC_G1_MISSING_GRP_KEY = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 13;
        internal const int WLAN_REASON_CODE_MSMSEC_PEER_INDICATED_INSECURE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 14;
        internal const int WLAN_REASON_CODE_MSMSEC_NO_AUTHENTICATOR = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 15;
        internal const int WLAN_REASON_CODE_MSMSEC_NIC_FAILURE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 16;
        internal const int WLAN_REASON_CODE_MSMSEC_CANCELLED = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 17;
        internal const int WLAN_REASON_CODE_MSMSEC_KEY_FORMAT = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 18;
        internal const int WLAN_REASON_CODE_MSMSEC_DOWNGRADE_DETECTED = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 19;
        internal const int WLAN_REASON_CODE_MSMSEC_PSK_MISMATCH_SUSPECTED = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 20;
        internal const int WLAN_REASON_CODE_MSMSEC_FORCED_FAILURE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 21;
        internal const int WLAN_REASON_CODE_MSMSEC_SECURITY_UI_FAILURE = WLAN_REASON_CODE_MSMSEC_CONNECT_BASE + 22;
        internal const int WLAN_REASON_CODE_MSMSEC_MAX = WLAN_REASON_CODE_MSMSEC_END;

        internal const int WLAN_AVAILABLE_NETWORK_CONNECTED = 0x00000001;
        internal const int WLAN_AVAILABLE_NETWORK_HAS_PROFILE = 0x00000002;
        internal const int WLAN_AVAILABLE_NETWORK_CONSOLE_USER_PROFILE = 0x00000004;
        internal const int WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES = 0x00000001;
        internal const int WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES = 0x00000002;

        internal const int DOT11_RATE_SET_MAX_LENGTH = 126; // 126 bytes
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WLAN_RATE_SET
        {
            internal int uRateSetLength;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = DOT11_RATE_SET_MAX_LENGTH)]
            internal ushort[] usRateSet;
        };

        internal const int WLAN_MAX_PHY_TYPE_NUMBER = 8;
        [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
        internal struct WlanAvailableNetwork
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = WLAN_MAX_NAME_LENGTH)]
            internal String strProfileName;
            internal DOT11_SSID dot11Ssid;
            internal DOT11_BSS_TYPE dot11BssType;
            internal int uNumberOfBssids;
            internal int bNetworkConnectable;
            internal uint wlanNotConnectableReason;
            internal int uNumberOfPhyTypes;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = WLAN_MAX_PHY_TYPE_NUMBER)]
            internal DOT11_PHY_TYPE[] dot11PhyTypes;
            internal int bMorePhyTypes;
            internal int wlanSignalQuality;
            internal int bSecurityEnabled;
            internal Dot11AuthenticationAlgorithm dot11DefaultAuthAlgorithm;
            internal Dot11CipherAlgorithm dot11DefaultCipherAlgorithm;
            internal uint dwFlags;
            internal uint dwReserved;
        };

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WLAN_BSS_ENTRY
        {
            internal DOT11_SSID dot11Ssid;
            internal int uPhyId;

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public byte[] dot11Bssid;

            internal DOT11_BSS_TYPE dot11BssType;
            internal DOT11_PHY_TYPE dot11BssPhyType;
            internal int lRssi;
            internal int uLinkQuality;
            internal bool bInRegDomain;
            internal ushort usBeaconPeriod;
            internal ulong ullTimestamp;
            internal ulong ullHostTimestamp;
            internal ushort usCapabilityInformation;
            internal int ulChCenterFrequency;
            internal WLAN_RATE_SET wlanRateSet;
            internal int ulIeOffset;
            internal int ulIeSize;
        };

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WLAN_BSS_LIST
        {
            internal uint dwTotalSize;
            internal uint dwNumberOfItems;
            [MarshalAs(UnmanagedType.ByValArray)]
            internal WLAN_BSS_ENTRY[] wlanBssEntries;
        };

        [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
        internal struct WlanInterfaceInfo
        {
            internal Guid InterfaceGuid;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = WLAN_MAX_NAME_LENGTH)]
            internal String strInterfaceDescription;
            internal WlanInterfaceState isState;
        };
        /*
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_ASSOCIATION_ATTRIBUTES
        {
           internal DOT11_SSID dot11Ssid;
           internal DOT11_BSS_TYPE dot11BssType;
           internal DOT11_MAC_ADDRESS dot11Bssid;
           internal DOT11_PHY_TYPE dot11PhyType;
           internal int uDot11PhyIndex;
           internal int wlanSignalQuality;
           internal int ulRxRate;
           internal int ulTxRate;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_SECURITY_ATTRIBUTES
        {
           internal int bSecurityEnabled;
           internal int bOneXEnabled;
           internal DOT11_AUTH_ALGORITHM dot11AuthAlgorithm;
           internal DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_CONNECTION_ATTRIBUTES
        {
           internal Wlan_Interface_State isState;
           internal WLAN_CONNECTION_MODE wlanConnectionMode;
           [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=WLAN_MAX_NAME_LENGTH)]
           internal string strProfileName;
           internal WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes;
           internal WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes;
        };

        internal const int WLAN_MAX_PHY_INDEX = 64;
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_PHY_RADIO_STATE
        {
           internal uint dwPhyIndex;
           internal Wlan_Interface_State dot11SoftwareRadioState;
           internal Wlan_Interface_State dot11HardwareRadioState;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_RADIO_STATE
        {
           internal uint dwNumberOfPhys;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=WLAN_MAX_PHY_INDEX)]
           internal WLAN_PHY_RADIO_STATE [] PhyRadioState;
        };

        internal enum WLAN_INTERFACE_TYPE
        {
           wlan_interface_type_emulated_802_11 = 0,
           wlan_interface_type_native_802_11,
           wlan_interface_type_invalid,
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_INTERFACE_CAPABILITY
        {
           internal WLAN_INTERFACE_TYPE interfaceType;
           internal int bDot11DSupported;
           internal uint dwMaxDesiredSsidListSize;
           internal uint dwMaxDesiredBssidListSize;
           internal uint dwNumberOfSupportedPhys;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=WLAN_MAX_PHY_INDEX)]
           internal DOT11_PHY_TYPE [] dot11PhyTypes;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_AUTH_CIPHER_PAIR_LIST
        {
           internal uint dwNumberOfItems;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=unique, size_is(dwNumberOfItems))]
           internal DOT11_AUTH_CIPHER_PAIR [][] pAuthCipherPairList;
           //[ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
           //internal DOT11_AUTH_CIPHER_PAIR [] pAuthCipherPairList;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_COUNTRY_OR_REGION_STRING_LIST
        {
           internal uint dwNumberOfItems;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=unique, size_is(dwNumberOfItems))]
           internal DOT11_COUNTRY_OR_REGION_STRING [] pCountryOrRegionStringList[*];
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
           internal DOT11_COUNTRY_OR_REGION_STRING [] pCountryOrRegionStringList;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_PROFILE_INFO_LIST
        {
           internal uint dwNumberOfItems;
           internal uint dwIndex;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=unique, size_is(dwNumberOfItems))]
           internal WLAN_PROFILE_INFO [] ProfileInfo[*];
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
           internal WLAN_PROFILE_INFO [] ProfileInfo;
        };
        */
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WlanAvailableNetworkList
        {
            internal uint dwNumberOfItems;
            internal uint dwIndex;
            [MarshalAs(UnmanagedType.ByValArray)]
            internal WlanAvailableNetwork[] Networks;
        };

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct WlanInterfaceInfoList
        {
            internal Int32 dwNumberOfItems;
            internal Int32 dwIndex;
            [MarshalAs(UnmanagedType.ByValArray)]
            internal WlanInterfaceInfo[] InterfaceInfo;
        };
        /*
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct DOT11_NETWORK_LIST
        {
           internal uint dwNumberOfItems;
           internal uint dwIndex;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=unique, size_is(dwNumberOfItems))]
           internal DOT11_NETWORK [] Network[*];
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
           internal __field_ecount(dwNumberOfItems) DOT11_NETWORK [] Network;
        };*/

        //[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        //public struct NDIS_OBJECT_HEADER
        //{
        //    public string Type;
        //    public string Revision;
        //    public ushort Size;
        //}

        //public struct DOT11_BSSID_LIST
        //{
        //    public NDIS_OBJECT_HEADER Header;
        //    public uint uNumOfEntries;
        //    public uint uTotalNumOfEntries;
        //    public DOT11_MAC_ADDRESS[] BSSIDs;
        //}

        internal const int WLAN_CONNECTION_HIDDEN_NETWORK = 0x00000001;
        internal const int WLAN_CONNECTION_ADHOC_JOIN_ONLY = 0x00000002;
        internal const int WLAN_CONNECTION_IGNORE_PRIVACY_BIT = 0x00000004;

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct WLAN_CONNECTION_PARAMETERS
        {
            public WLAN_CONNECTION_MODE wlanConnectionMode;
            public string strProfile;
            public IntPtr pDot11Ssid;
            public IntPtr pDesiredBssidList;
            public DOT11_BSS_TYPE dot11BssType;
            public uint dwFlags;
        }

        /*
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_MSM_NOTIFICATION_DATA
        {
           internal WLAN_CONNECTION_MODE wlanConnectionMode;
           [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=WLAN_MAX_NAME_LENGTH)]
           internal string strProfileName;
           internal DOT11_SSID dot11Ssid;
           internal DOT11_BSS_TYPE dot11BssType;
           internal DOT11_MAC_ADDRESS dot11MacAddr;
           internal int bSecurityEnabled;
           internal int bFirstPeer;
           internal int bLastPeer;
           internal uint wlanReasonCode;
        };

        internal const int WLAN_CONNECTION_NOTIFICATION_ADHOC_NETWORK_FORMED = 0x00000001;
        internal const int WLAN_CONNECTION_NOTIFICATION_CONSOLE_USER_PROFILE = 0x00000004;
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_CONNECTION_NOTIFICATION_DATA
        {
           internal WLAN_CONNECTION_MODE wlanConnectionMode;
           [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=WLAN_MAX_NAME_LENGTH)]
           internal string strProfileName;
           internal DOT11_SSID dot11Ssid;
           internal DOT11_BSS_TYPE dot11BssType;
           internal int bSecurityEnabled;
           internal uint wlanReasonCode;
           internal uint dwFlags;
           [ MarshalAs( UnmanagedType.ByValTStr, SizeConst=1)]
           internal string strProfileXml;
        };

        internal const int WLAN_NOTIFICATION_SOURCE_NONE = L2_NOTIFICATION_SOURCE_NONE;
        internal const int WLAN_NOTIFICATION_SOURCE_ALL = L2_NOTIFICATION_SOURCE_AL;
        internal const int WLAN_NOTIFICATION_SOURCE_ACM = L2_NOTIFICATION_SOURCE_WLAN_ACM;
        internal const int WLAN_NOTIFICATION_SOURCE_MSM = L2_NOTIFICATION_SOURCE_WLAN_MSM;
        internal const int WLAN_NOTIFICATION_SOURCE_SECURITY = L2_NOTIFICATION_SOURCE_WLAN_SECURITY;
        internal const int WLAN_NOTIFICATION_SOURCE_IHV = L2_NOTIFICATION_SOURCE_WLAN_IHV;
        internal enum WLAN_FILTER_LIST_TYPE
        {
           wlan_filter_list_type_gp_permit,
           wlan_filter_list_type_gp_deny,
           wlan_filter_list_type_user_permit,
           wlan_filter_list_type_user_deny,
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_PHY_FRAME_STATISTICS
        {
           internal ULONGLONG ullTransmittedFrameCount;
           internal ULONGLONG ullMulticastTransmittedFrameCount;
           internal ULONGLONG ullFailedCount;
           internal ULONGLONG ullRetryCount;
           internal ULONGLONG ullMultipleRetryCount;
           internal ULONGLONG ullMaxTXLifetimeExceededCount;
           internal ULONGLONG ullTransmittedFragmentCount;
           internal ULONGLONG ullRTSSuccessCount;
           internal ULONGLONG ullRTSFailureCount;
           internal ULONGLONG ullACKFailureCount;
           internal ULONGLONG ullReceivedFrameCount;
           internal ULONGLONG ullMulticastReceivedFrameCount;
           internal ULONGLONG ullPromiscuousReceivedFrameCount;
           internal ULONGLONG ullMaxRXLifetimeExceededCount;
           internal ULONGLONG ullFrameDuplicateCount;
           internal ULONGLONG ullReceivedFragmentCount;
           internal ULONGLONG ullPromiscuousReceivedFragmentCount;
           internal ULONGLONG ullFCSErrorCount;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_MAC_FRAME_STATISTICS
        {
           internal ULONGLONG ullTransmittedFrameCount;
           internal ULONGLONG ullReceivedFrameCount;
           internal ULONGLONG ullWEPExcludedCount;
           internal ULONGLONG ullTKIPLocalMICFailures;
           internal ULONGLONG ullTKIPReplays;
           internal ULONGLONG ullTKIPICVErrorCount;
           internal ULONGLONG ullCCMPReplays;
           internal ULONGLONG ullCCMPDecryptErrors;
           internal ULONGLONG ullWEPUndecryptableCount;
           internal ULONGLONG ullWEPICVErrorCount;
           internal ULONGLONG ullDecryptSuccessCount;
           internal ULONGLONG ullDecryptFailureCount;
        };

        [StructLayout(LayoutKind.Sequential,Pack=4)]
        internal struct WLAN_STATISTICS
        {
           internal ULONGLONG ullFourWayHandshakeFailures;
           internal ULONGLONG ullTKIPCounterMeasuresInvoked;
           internal ULONGLONG ullReserved;
           internal WLAN_MAC_FRAME_STATISTICS MacUcastCounters;
           internal WLAN_MAC_FRAME_STATISTICS MacMcastCounters;
           internal uint dwNumberOfPhys;
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=unique, size_is(dwNumberOfPhys))]
           internal WLAN_PHY_FRAME_STATISTICS [] PhyCounters[*];
           [ MarshalAs( UnmanagedType.ByValArray, SizeConst=1)]
           internal WLAN_PHY_FRAME_STATISTICS [] PhyCounters;
        };

        internal const int WLAN_READ_ACCESS = FILE_READ_DATA;
        internal const int WLAN_EXECUTE_ACCESS = FILE_EXECUTE;
        internal const int WLAN_WRITE_ACCESS = WRITE_DAC;
        internal enum WLAN_SECURABLE_OBJECT
        {
           wlan_secure_permit_list = 0,
           wlan_secure_deny_list,
           wlan_secure_ac_enabled,
           wlan_secure_bc_scan_enabled,
           wlan_secure_bss_type,
           wlan_secure_show_denied,
           wlan_secure_interface_properties,
           wlan_secure_ihv_control,
           wlan_secure_all_user_profiles_order,
           wlan_secure_add_new_all_user_profiles,
           wlan_secure_add_new_per_user_profiles,
           wlan_secure_media_streaming_mode_enabled,
           wlan_secure_current_operation_mode,
           WLAN_SECURABLE_OBJECT_COUNT,
        };
        */

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanOpenHandle(Int32 dwClientVersion, Int32 pReserved, out Int32 pdwNegotiatedVersion, out IntPtr phClientIntPtr);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanCloseHandle(IntPtr hClientIntPtr, Int32 pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanEnumInterfaces(IntPtr hClientIntPtr, Int32 pReserved, out IntPtr ppInterfaceList); //WLAN_INTERFACE_INFO_LIST
        /*
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetAutoConfigParameter (IntPtr hClientIntPtr, WLAN_AUTOCONF_OPCODE OpCode, Int32 dwDataSize, __in_bcount param3);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanQueryAutoConfigParameter (IntPtr hClientIntPtr, WLAN_AUTOCONF_OPCODE OpCode, IntPtr pReserved, out PInt32 pdwDataSize, __deref_out_bcount param4);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetInterfaceCapability (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, IntPtr pReserved, ref PWLAN_INTERFACE_CAPABILITY ppCapability);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetInterface (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, WLAN_INTF_OPCODE OpCode, Int32 dwDataSize, __in_bcount param4);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanQueryInterface (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, WLAN_INTF_OPCODE OpCode, IntPtr pReserved, out PInt32 pdwDataSize, __deref_out_bcount param5);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanIhvControl (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, WLAN_IHV_CONTROL_TYPE Type, Int32 dwInBufferSize, __in_bcount param4);
        */
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanScan(IntPtr hClientIntPtr, ref Guid pInterfaceGuid, IntPtr pDot11Ssid, out IntPtr pWlanRawData, Int32 pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetAvailableNetworkList(IntPtr hClientIntPtr, ref Guid pInterfaceGuid, Int32 dwFlags, Int32 pReserved, out IntPtr ppAvailableNetworkList); //PWLAN_AVAILABLE_NETWORK_LIST

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetNetworkBssList(IntPtr hClientIntPtr, ref Guid pInterfaceGuid, IntPtr pDot11Ssid, DOT11_BSS_TYPE dot11BssType, bool bSecurityEnabled, Int32 pReserved, out IntPtr ppWlanBssList); //PWLAN_BSS_LIST

        [DllImport("wlanapi.dll", CharSet = CharSet.Unicode)]
        internal static extern uint WlanConnect(IntPtr hClientHandle, ref Guid pInterfaceGuid, ref WLAN_CONNECTION_PARAMETERS pConnectionParameters, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanDisconnect(IntPtr hClientIntPtr, ref Guid pInterfaceGuid, Int32 pReserved);
        /*
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanRegisterNotification (IntPtr hClientIntPtr, Int32 dwNotifSource, BOOL bIgnoreDuplicate, WLAN_NOTIFICATION_CALLBACK funcCallback, IntPtr pCallbackContext, IntPtr pReserved, PInt32 pdwPrevNotifSource);
        */
        [DllImport("wlanapi.dll", CharSet = CharSet.Unicode)]
        internal static extern uint WlanGetProfile(IntPtr hClientHandle, ref Guid pInterfaceGuid, string strProfileName, IntPtr pReserved, ref string pstrProfileXml, ref uint pdwFlags, ref uint pdwGrantedAccess);
        /*
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfileEapUserData (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, EAP_METHOD_TYPE eapType, Int32 dwFlags, Int32 dwEapUserDataSize, __in_bcount param6);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfileEapXmlUserData (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, Int32 dwFlags, LPCWSTR strEapXmlUserData, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfile (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, Int32 dwFlags, LPCWSTR strProfileXml, LPCWSTR strAllUserProfileSecurity, BOOL bOverwrite, IntPtr pReserved, ref Int32 pdwReasonCode);
        */
        [DllImport("wlanapi.dll", CharSet = CharSet.Unicode)]
        internal static extern uint WlanDeleteProfile(IntPtr hClientIntPtr, ref Guid pInterfaceGuid, string strProfileName, IntPtr pReserved);
        /*
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanRenameProfile (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strOldProfileName, LPCWSTR strNewProfileName, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetProfileList (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, IntPtr pReserved, ref PWLAN_PROFILE_INFO_LIST ppProfileList);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfileList (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, Int32 dwItems, __in_ecount param3);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfilePosition (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, Int32 dwPosition, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetProfileCustomUserData (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, Int32 dwDataSize, __in_bcount param4);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetProfileCustomUserData (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, IntPtr pReserved, ref Int32 pdwDataSize, __deref_out_bcount param5);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetFilterList (IntPtr hClientIntPtr, WLAN_FILTER_LIST_TYPE wlanFilterListType, PDOT11_NETWORK_LIST pNetworkList, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetFilterList (IntPtr hClientIntPtr, WLAN_FILTER_LIST_TYPE wlanFilterListType, IntPtr pReserved, ref PDOT11_NETWORK_LIST ppNetworkList);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetPsdIEDataList (IntPtr hClientIntPtr, LPCWSTR strFormat, PWLAN_RAW_DATA_LIST pPsdIEDataList, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSaveTemporaryProfile (IntPtr hClientIntPtr, ref GUID pInterfaceGuid, LPCWSTR strProfileName, LPCWSTR strAllUserProfileSecurity, Int32 dwFlags, BOOL bOverWrite, IntPtr pReserved);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanExtractPsdIEDataList (IntPtr hClientIntPtr, Int32 dwIeDataSize, __in_bcount param2);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanReasonCodeToString (Int32 dwReasonCode, Int32 dwBufferSize, __in_ecount param2);
        
        [DllImport("wlanapi.dll")]
        internal static extern IntPtr WlanAllocateMemory (Int32 dwMemorySize);
        */
        [DllImport("wlanapi.dll")]
        internal static extern void WlanFreeMemory(IntPtr pMemory);
        /*
        [DllImport("wlanapi.dll")]
        internal static extern uint WlanSetSecuritySettings (IntPtr hClientIntPtr, WLAN_SECURABLE_OBJECT SecurableObject, LPCWSTR strModifiedSDDL);

        [DllImport("wlanapi.dll")]
        internal static extern uint WlanGetSecuritySettings (IntPtr hClientIntPtr, WLAN_SECURABLE_OBJECT SecurableObject, PWLAN_OPCODE_VALUE_TYPE pValueType, ref LPWSTR pstrCurrentSDDL, out PInt32 pdwGrantedAccess);
        */
        internal const int WLAN_UI_API_VERSION = 1;
        internal const int WLAN_UI_API_INITIAL_VERSION = 1;
        internal enum WL_DISPLAY_PAGES
        {
           WLConnectionPage,
           WLSecurityPage,
        };

        [DllImport("wlanui.dll", CharSet = CharSet.Unicode)]
        internal static extern uint WlanUIEditProfile(Int32 dwClientVersion, string wstrProfileName, ref Guid pInterfaceGuid, IntPtr hWnd, WL_DISPLAY_PAGES wlStartPage, IntPtr pReserved, ref int pWlanReasonCode);

        /***
         * WLanTypes.h
         **/
        internal enum DOT11_BSS_TYPE
        {
            dot11_BSS_type_infrastructure = 1,
            dot11_BSS_type_independent = 2,
            dot11_BSS_type_any = 3
        }

        internal const int DOT11_SSID_MAX_LENGTH = 32;      // 32 bytes
        internal struct DOT11_SSID
        {
            internal Int32 SSIDLength;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = DOT11_SSID_MAX_LENGTH)]
            internal String SSID;
        }


        // DOT11_AUTH_ALGO_LIST

        internal enum Dot11AuthenticationAlgorithm
        {
            _80211_OPEN = 1,
            _80211_SHARED_KEY = 2,
            WPA = 3,
            WPA_PSK = 4,
            WPA_NONE = 5,               // used in NatSTA only
            RSNA = 6,
            RSNA_PSK = 7
            //IHV_START = (int)0x80000000,
            //IHV_END = (int)0xffffffff
        }

        //internal const int DOT11_AUTH_ALGORITHM_OPEN_SYSTEM = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_80211_OPEN;
        //internal const int DOT11_AUTH_ALGORITHM_SHARED_KEY = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_80211_SHARED_KEY;
        //internal const int DOT11_AUTH_ALGORITHM_WPA = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_WPA;
        //internal const int DOT11_AUTH_ALGORITHM_WPA_PSK = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_WPA_PSK;
        //internal const int DOT11_AUTH_ALGORITHM_WPA_NONE = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_WPA_NONE;
        //internal const int DOT11_AUTH_ALGORITHM_RSNA = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_RSNA;
        //internal const int DOT11_AUTH_ALGORITHM_RSNA_PSK = (int)Dot11AuthenticationAlgorithm.DOT11_AUTH_ALGO_RSNA_PSK;

        // Cipher algorithm Ids (for little endian platform)
        internal enum Dot11CipherAlgorithm
        {
            NONE = 0x00,
            WEP40 = 0x01,
            TKIP = 0x02,
            CCMP = 0x04,
            WEP104 = 0x05,
            WPA_USE_GROUP = 0x100,
            RSN_USE_GROUP = 0x100,
            WEP = 0x101
            //IHV_START = 0x80000000,
            //IHV_END = 0xffffffff
        }

        //internal struct DOT11_AUTH_CIPHER_PAIR
        //{
        //    Dot11AuthenticationAlgorithm AuthAlgoId;
        //    Dot11CipherAlgorithm CipherAlgoId;
        //}


        /****
         * WinDot11.h
         */
        internal enum DOT11_PHY_TYPE
        {
            dot11_phy_type_unknown = 0,
            dot11_phy_type_any = dot11_phy_type_unknown,
            dot11_phy_type_fhss = 1,
            dot11_phy_type_dsss = 2,
            dot11_phy_type_irbaseband = 3,
            dot11_phy_type_ofdm = 4,
            dot11_phy_type_hrdsss = 5,
            dot11_phy_type_erp = 6
            //dot11_phy_type_IHV_start = 0x80000000,
            //dot11_phy_type_IHV_end = 0xffffffff
        }

        /****
         * L2Cmn.h
         */
        internal const int L2_PROFILE_MAX_NAME_LENGTH = 256;
        internal const int L2_NOTIFICATION_SOURCE_NONE = 0;
        internal const int L2_NOTIFICATION_SOURCE_DOT3_AUTO_CONFIG = 0X00000001;
        internal const int L2_NOTIFICATION_SOURCE_SECURITY = 0X00000002;
        internal const int L2_NOTIFICATION_SOURCE_ONEX = 0X00000004;
        internal const int L2_NOTIFICATION_SOURCE_WLAN_ACM = 0X00000008;
        internal const int L2_NOTIFICATION_SOURCE_WLAN_MSM = 0X00000010;
        internal const int L2_NOTIFICATION_SOURCE_WLAN_SECURITY = 0X00000020;
        internal const int L2_NOTIFICATION_SOURCE_WLAN_IHV = 0X00000040;
        internal const int L2_NOTIFICATION_SOURCE_ALL = 0X0000FFFF;
        internal const int L2_NOTIFICATION_CODE_PUBLIC_BEGIN = 0X00000000;
        internal const int L2_REASON_CODE_GROUP_SIZE = 0x10000;
        internal const int L2_REASON_CODE_GEN_BASE = 0x10000;
        internal const int L2_REASON_CODE_DOT11_AC_BASE = L2_REASON_CODE_GEN_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_DOT11_MSM_BASE = L2_REASON_CODE_DOT11_AC_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_DOT11_SECURITY_BASE = L2_REASON_CODE_DOT11_MSM_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_ONEX_BASE = L2_REASON_CODE_DOT11_SECURITY_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_DOT3_AC_BASE = L2_REASON_CODE_ONEX_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_DOT3_MSM_BASE = L2_REASON_CODE_DOT3_AC_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_PROFILE_BASE = L2_REASON_CODE_DOT3_MSM_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_IHV_BASE = L2_REASON_CODE_PROFILE_BASE + L2_REASON_CODE_GROUP_SIZE;
        internal const int L2_REASON_CODE_SUCCESS = 0;
        internal const int L2_REASON_CODE_UNKNOWN = L2_REASON_CODE_GEN_BASE + 1;
        internal const int L2_REASON_CODE_PROFILE_MISSING = 0x00000001;

        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        internal struct L2_NOTIFICATION_DATA
        {
            internal uint NotificationSource;
            internal uint NotificationCode;
            internal Guid InterfaceGuid;
            internal uint dwDataSize;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)]  // dwDataSize
            internal byte[] pData;
        };
    }
}